﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;
using Microsoft.Extensions.Configuration;
using System.Text;

namespace WebApplication1
{
    public class HomeController : Controller
    {
        private IConfiguration _configuration;

        public HomeController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        public IActionResult Index()
        {

            StringBuilder sb = new StringBuilder();

            var client = new MongoClient(_configuration.GetSection("MongoConfig").Value);

            IMongoDatabase database=client.GetDatabase("abc");

            var collection = database.GetCollection<BsonDocument>("aa");

            var list=collection.Find<BsonDocument>(a=>true).ToList();


            foreach (var item in list)
            {
                sb.Append(item.AsBsonValue);
            }


            return Content(sb.ToString());
        }
    }
}
